<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 每页条数
     */
    const PAGESIZE = 20;

    /**
     * 视图
     * @param null $view
     * @param array $data
     * @param array $mergeData
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     */
    protected function view($view = null, $data = [], $mergeData = [])
    {
        $theme = config('jishupucms.view_theme');
        if ($view != null) {
            $view = trim($theme, '/') . "/" . ltrim($view, '/');
        }
        return view($view, $data, $mergeData);
    }

    /**
     * 检查视图是否存在
     * @param null $view
     * @return bool
     */
    protected function existView($view = null)
    {
        if (!$view) return false;
        $theme = config('jishupucms.view_theme');
        $view = trim($theme, '/') . "/" . ltrim($view, '/');
        return view()->exists($view);
    }
}
